package com.ruoyi.project.business.asynctask.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.business.asynctask.mapper.BusinessAsyncTaskMapper;
import com.ruoyi.project.business.asynctask.entity.BusinessAsyncTask;
import com.ruoyi.project.business.asynctask.request.ListBusinessAsyncTaskRequest;
import com.ruoyi.project.business.asynctask.request.AddBusinessAsyncTaskRequest;
import com.ruoyi.project.business.asynctask.response.BusinessAsyncTaskResponse;
import com.ruoyi.project.business.asynctask.service.IBusinessAsyncTaskService;

/**
 * 任务状态Service业务层处理
 * 
 * @author ${author}
 * @date 2024-04-11
 */
@Service
public class BusinessAsyncTaskServiceImpl implements IBusinessAsyncTaskService {
    @Autowired
    private BusinessAsyncTaskMapper businessAsyncTaskMapper;

    /**
     * 查询任务状态
     * 
     * @return 任务状态
     */
    @Override
    public BusinessAsyncTask selectBusinessAsyncTaskById(Long id) {
        return businessAsyncTaskMapper.selectBusinessAsyncTaskById(id);
    }

    /**
     * 查询任务状态列表
     * 
     * @return 任务状态
     */
    @Override
    public List<BusinessAsyncTaskResponse> selectBusinessAsyncTaskList(ListBusinessAsyncTaskRequest request, Long tenantId) {
        // TODO request to  param
        BusinessAsyncTask param = BeanUtils.copy(request, BusinessAsyncTask.class);
        param.setTenantId(tenantId);
        List<BusinessAsyncTask> entitis = businessAsyncTaskMapper.selectBusinessAsyncTaskList(param);
        List<BusinessAsyncTaskResponse> resList = BeanUtils.copyList(entitis, BusinessAsyncTaskResponse.class);
        return resList;
    }

    /**
     * 新增任务状态
     * 
     * @return 结果
     */
    @Override
    public int insertBusinessAsyncTask(AddBusinessAsyncTaskRequest request, Long operatorId, Long tenantId) {
        BusinessAsyncTask entity = BeanUtils.copy(request, BusinessAsyncTask.class);
        entity.setTenantId(tenantId);
        entity.setCreator(operatorId);
        entity.setDeleted(Boolean.FALSE);
        entity.setCreateTime(DateUtils.getNowDate());
        return businessAsyncTaskMapper.insertBusinessAsyncTask(entity);
    }

    /**
     * 修改任务状态
     * 
     * @return 结果
     */
    @Override
    public int updateBusinessAsyncTask(BusinessAsyncTask entity, Long operatorId, Long tenantId) {
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setTenantId(tenantId);
        entity.setUpdater(operatorId);
        return businessAsyncTaskMapper.updateBusinessAsyncTask(entity);
    }

    /**
     * 批量删除任务状态
     * 
     * @return 结果
     */
    @Override
    public int deleteBusinessAsyncTaskByIds(Long[] ids, Long operatorId, Long tenantId) {
        return businessAsyncTaskMapper.deleteBusinessAsyncTaskByIds(ids);
    }

    /**
     * 删除任务状态信息
     * 
     * @return 结果
     */
    @Override
    public int deleteBusinessAsyncTaskById(Long id, Long operatorId, Long tenantId) {
        return businessAsyncTaskMapper.deleteBusinessAsyncTaskById(id);
    }
}
